<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initDb() {
		Zend_Session::start(true);     
        $dbOption = $this->getOption('resources');
	    $dbOption = $dbOption['db'];
	
	    // Setup database
	    $db = Zend_Db::factory($dbOption['adapter'], $dbOption['params']);
	
	    $db->setFetchMode(Zend_Db::FETCH_ASSOC);
	    $db->query("SET NAMES 'utf8'");
	    $db->query("SET CHARACTER SET 'utf8'");
	
	    Zend_Registry::set('vicdbsystem', $db);
	
	    //Khi thiet lap che do nay model moi co the su dung duoc
	    Zend_Db_Table::setDefaultAdapter($db);
	    // Return it, so that it can be stored by the bootstrap
	    
	    return $db;
	}
	protected function _initRoutes(){
		$frontController = Zend_Controller_Front::getInstance();
		$router = new Zend_Controller_Router_Rewrite();
		//regex
		$router->addRoute('product details',
		 new Zend_Controller_Router_Route_Regex(
		 '(.*)/(.*)/(.*)/(.*)-(.*).p\.html', 
		 array('lang'=>'vi','module'=>'front','controller'=>'product','action'=>'details'), 
		 array('1'=>'storealias','2'=>'typealias','3'=>'catalias','4'=>'proalias','5'=>'proid'))
		 );
		 $router->addRoute('product cat',
		 new Zend_Controller_Router_Route_Regex(
		 '(.*)/(.*)/(.*)-(.*).c\.html', 
		 array('lang'=>'vi','module'=>'front','controller'=>'product','action'=>'catalogue'), 
		 array('1'=>'storealias','2'=>'typealias','3'=>'catalias','4'=>'catid'))
		 );
		 $router->addRoute('product type',
		 new Zend_Controller_Router_Route_Regex(
		 '(.*)/(.*)-(.*).t\.html', 
		 array('lang'=>'vi','module'=>'front','controller'=>'product','action'=>'type'), 
		 array('1'=>'storealias','2'=>'typealias','3'=>'typeid'))
		 );
		
		$frontController->setRouter($router);
	}
	protected function _initAutoload()
	{
		$autoloader = new Zend_Application_Module_Autoloader(array(
			'namespace' => '',
			'basePath'  => APPLICATION_PATH
		));
		return $autoloader;
	}
}